package com.base.app_core.ioc.module;


import com.base.app_core.App;
import com.base.app_core.model.dto.CosVo;
import com.base.app_core.service.user.model.User;
import com.base.app_core.util.liteorm.MyIChatDBHelpUtils;
import com.base.app_core.util.log.F;

import java.util.List;

import javax.inject.Singleton;

import dagger.Module;
import dagger.Provides;

/**
 * Created by jiansheng.li on 2017/4/26.
 */
@Module
public class AppModule {
    private App mInstance = null;

    public AppModule(App mInstance) {
        this.mInstance = mInstance;
    }

    @Provides
    @Singleton
    App provideApp() {
        return mInstance;
    }

    @Provides
    @Singleton
    MyIChatDBHelpUtils provideDB() {
        return new MyIChatDBHelpUtils();
    }

    @Provides
    @Singleton
    User provideUser(MyIChatDBHelpUtils myIChatDBHelpUtils) {//需要处理缓存。
        F.j("provideUser");
        List<User> users = myIChatDBHelpUtils.getQueryAll(User.class);
        User user = null;
        if (null != users && users.size() > 0)
            user = users.get(0);
        else
            user = new User();
        myIChatDBHelpUtils.setUser(user);
        return user;
    }

    @Provides
    @Singleton
    CosVo provideCosVo() {
        return new CosVo();
    }


//    @Provides
//    @Singleton
//    PushAgent providePushAgent(final User user, App app){
////        UMConfigure.setLogEnabled(true);
//        //初始化组件化基础库, 统计SDK/推送SDK/分享SDK都必须调用此初始化接口
////        UMConfigure.init(app, "5a77c945b27b0a34cf000031", "Umeng", UMConfigure.DEVICE_TYPE_PHONE, "d1e3df753c94ba1f7c8c20b3500ef093");
//        //开启ShareSDK debug模式，方便定位错误，具体错误检查方式可以查看http://dev.umeng.com/social/android/quick-integration的报错必看，正式发布，请关闭该模式
////        Config.DEBUG = true;
//
//        PushAgent mPushAgent = PushAgent.getInstance(app);
//        mPushAgent.setNotificationPlaySound(MsgConstant.NOTIFICATION_PLAY_SDK_ENABLE);
//        mPushAgent.register(new IUmengRegisterCallback() {//注册推送服务，每次调用register方法都会回调该接口
//            @Override
//            public void onSuccess(String deviceToken) {
//                //注册成功会返回device token
//                F.http("deviceToke:"+deviceToken);
//                if(user!=null)
//                    user.setUMengDeviceToken(deviceToken);
//            }
//            @Override
//            public void onFailure(String s, String s1) {
//                F.http("s:"+s+" s1:"+s1);
//            }
//        });
//        return mPushAgent;
//    }
}
